//
//  JkmTabBar.swift
//  SinaWb
//
//  Created by Jiang on 16/5/8.
//  Copyright © 2016年 Jiang. All rights reserved.
//

import UIKit

class JkmTabBar: UITabBar {
    var composeButton = UIButton(imageName: "tabbar_compose_icon_add", backimageName: "tabbar_compose_button")
 
    override func layoutSubviews() {
        super.layoutSubviews()
        let  h  = frame.size.height
//  **        如果不在tabbarcontroller 中添加一个空视图站位则使用下面代码
        var  x : CGFloat = 0
        let  y : CGFloat = 0
        let  w = frame.size.width / CGFloat ((items?.count)! + 1)
        var index :CGFloat = 0
        for tabbarbutton in subviews {
            if tabbarbutton.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                x  = w*index
                
                tabbarbutton.frame = CGRect(x: x, y: y, width: w, height: h)
                
//                if index == 1 {
//                    index++
//                }
//                index++
                
                //三目
                index += (index == 1) ? 2 : 1
                
            }
        }
//  **
        composeButton.center = CGPoint(x: frame.size.width * 0.5, y: h * 0.5)
        
        bringSubviewToFront(composeButton)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addsubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
       super.init(coder: aDecoder)
        addsubviews()
    }
    private func addsubviews(){
        addSubview(composeButton)
        
    }
    
   
}
